﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace BanVeXemPhim_Presentation
{
    public class TheLoaiDAO : DataProvider
    {
        public TheLoaiDTO[] LayDanhSachTheLoai()
        {
            connect();
            string query = "select * from theloai";
            adapter = new SqlDataAdapter(query, connection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet);
            DataTable dataTable = dataSet.Tables[0];
            int n = dataTable.Rows.Count;
            TheLoaiDTO[] TheLoaiDto = new TheLoaiDTO[n];
            for (int i = 0; i < n; i++)
            {
                TheLoaiDto[i] = (TheLoaiDTO)GetDataFromDataRow(dataTable, i);
            }
            return TheLoaiDto;
        }
        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            TheLoaiDTO theloaiDto = new TheLoaiDTO();
            theloaiDto.IdTheLoai = Convert.ToInt32(dt.Rows[i]["Idtheloai"].ToString());
            theloaiDto.TenTheLoai = dt.Rows[i]["TenTheLoai"].ToString();
            return theloaiDto;
        }
    }
}
